package com.ledi.guns.modular.ledipay.service.impl;

import java.io.IOException;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

import javax.annotation.Resource;
import javax.mail.internet.MimeMessage;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.collections.CollectionUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.freemarker.FreeMarkerTemplateUtils;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.export.styler.ExcelExportStylerBorderImpl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.ledi.guns.common.exception.AppCheckException;
import com.ledi.guns.common.persistence.dao.AgentInfoMapper;
import com.ledi.guns.common.persistence.dao.BillDetailMapper;
import com.ledi.guns.common.persistence.dao.BillMapper;
import com.ledi.guns.common.persistence.dao.DeptMapper;
import com.ledi.guns.common.persistence.dao.RegionMapper;
import com.ledi.guns.common.persistence.dao.RoleMapper;
import com.ledi.guns.common.persistence.dao.SchoolInfoMapper;
import com.ledi.guns.common.persistence.dao.SchoolPayItemMapper;
import com.ledi.guns.common.persistence.dao.SmsSendMapper;
import com.ledi.guns.common.persistence.dao.UserMapper;
import com.ledi.guns.common.persistence.model.Bill;
import com.ledi.guns.common.persistence.model.SchoolInfo;
import com.ledi.guns.common.persistence.model.SchoolPayItem;
import com.ledi.guns.common.persistence.model.SmsSend;
import com.ledi.guns.common.persistence.model.TAgentInfo;
import com.ledi.guns.common.persistence.model.User;
import com.ledi.guns.common.persistence.model.vo.AccountVo;
import com.ledi.guns.common.persistence.model.vo.AgentNamesVo;
import com.ledi.guns.common.persistence.model.vo.CurrentFlowDataVo;
import com.ledi.guns.common.persistence.model.vo.CurrentSchoolDataVo;
import com.ledi.guns.common.persistence.model.vo.DayOrHourChargeCountVo;
import com.ledi.guns.common.persistence.model.vo.EveryDayCountVo;
import com.ledi.guns.common.persistence.model.vo.EveryFlowCountVo;
import com.ledi.guns.common.persistence.model.vo.EveryMonthSmsCountVo;
import com.ledi.guns.common.persistence.model.vo.ExportSchoolInfoVo;
import com.ledi.guns.common.persistence.model.vo.HotSchoolVo;
import com.ledi.guns.common.persistence.model.vo.SchoolAndFlowSituation;
import com.ledi.guns.common.persistence.model.vo.SchoolInfoVo;
import com.ledi.guns.common.persistence.model.vo.SchoolPayItemVo;
import com.ledi.guns.common.persistence.model.vo.SeeSchoolInfoVo;
import com.ledi.guns.common.persistence.model.vo.StatisticsSchoolVo;
import com.ledi.guns.common.util.KeyValue;
import com.ledi.guns.common.util.StringUtil;
import com.ledi.guns.core.shiro.ShiroKit;
import com.ledi.guns.core.shiro.ShiroUser;
import com.ledi.guns.core.util.DateUtil;
import com.ledi.guns.core.util.HttpUtil;
import com.ledi.guns.core.util.SystemConstans;
import com.ledi.guns.modular.ledipay.controller.req.agent.QueryHotData;
import com.ledi.guns.modular.ledipay.controller.req.agent.QuerySmsData;
import com.ledi.guns.modular.ledipay.controller.req.school.AddSchoolAccount;
import com.ledi.guns.modular.ledipay.controller.req.school.AddSchoolInfo;
import com.ledi.guns.modular.ledipay.controller.req.school.AddSchoolPayItem;
import com.ledi.guns.modular.ledipay.controller.req.school.EditAccount;
import com.ledi.guns.modular.ledipay.controller.req.school.EditSchoolInfo;
import com.ledi.guns.modular.ledipay.controller.req.school.QuerySchoolInfo;
import com.ledi.guns.modular.ledipay.controller.req.school.QuerySeeSchoolInfo;

import freemarker.template.Template;

/**
 * 学校管理Service
 *
 * @author fengshuonan
 * @Date 2017-11-29 09:30:10
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class SchoolServiceImpl extends ServiceImpl<SchoolInfoMapper, SchoolInfo> {

	private static final Logger logger = LoggerFactory.getLogger(ServiceImpl.class);

	@Value("${ledi.sms.url}")
	private String smsUrl;

	@Resource
	private SchoolInfoMapper schoolInfoMapper;

	@Resource
	private UserMapper userMapper;

	@Resource
	private EduPayCenter eduPayCenter;

	@Resource
	private BillDetailMapper billDetailMapper;

	@Resource
	private BillMapper billMapper;

	@Resource
	private AgentInfoMapper agentInfoMapper;

	@Resource
	private RoleMapper roleMapper;

	@Resource
	private DeptMapper deptMapper;

	@Resource
	private RegionMapper regionMapper;

	@Autowired
	private FreeMarkerConfigurer freeMarkerConfigurer;

	@Autowired
	private JavaMailSender mailSender;

	@Value("${spring.mail.username}")
	private String Sender;

	@Value("${ledi.mail.subject}")
	private String subject;

	@Autowired
	private SmsSendMapper smsSendMapper;

	@Autowired
	private SchoolPayItemMapper schoolPayItemMapper;

	/**
	 * 方法描述: [学校列表.]<br/>
	 * 初始作者: 钟小平<br/>
	 * 创建日期: 2018年7月18日-下午8:08:48<br/>
	 * 开始版本: 2.0.0<br/>
	 * =================================================<br/>
	 * 修改记录：<br/>
	 * 修改作者 日期 修改内容<br/>
	 * ================================================<br/>
	 * 
	 * @param page
	 * @param querySchoolInfo
	 * @return
	 *         Page<SchoolInfoVo>
	 */
	public Page<SchoolInfoVo> getSchoolInfoList(Page<SchoolInfoVo> page, QuerySchoolInfo querySchoolInfo) {

		extracted(querySchoolInfo);
		List<SchoolInfoVo> searchResult = schoolInfoMapper.getSchoolInfo(page, querySchoolInfo.getSearch());
		page.setRecords(searchResult);
		return page;
	}

	public void editAccount(EditAccount editAccount) {

		User user = userMapper.selectById(editAccount.getId());
		if (null == user) {
			throw new AppCheckException("school.selectUserError.code", "school.selectUserError.message");
		}
		user.setAccount(editAccount.getAccount());
		user.setSalt(ShiroKit.getRandomSalt(5));
		user.setPassword(ShiroKit.md5(editAccount.getNewPasswd(), user.getSalt()));
		Integer userUpdate = userMapper.updateById(user);
		if (userUpdate < 1) {
			throw new AppCheckException("school.updateUserError.code", "school.updateUserError.message");
		}
	}

	public List<AccountVo> getAccount(Long schoolId) {

		List<AccountVo> accountVos = schoolInfoMapper.getAccount(schoolId);
		return accountVos;
	}

	public void addSchoolAccount(AddSchoolAccount addSchoolAccount) {

		Date date = new Date();
		User user = new User();
		String account = addSchoolAccount.getAccount();
		Map<String, Object> map = new HashMap();
		map.put("account", account);
		List<User> selectByMap = userMapper.selectByMap(map);
		if (selectByMap.size() != 0) {
			throw new AppCheckException("school.userHaveExistError.code", "school.userHaveExistError.message");
		}
		user.setSalt(ShiroKit.getRandomSalt(5));
		user.setPassword(ShiroKit.md5(addSchoolAccount.getPassword(), user.getSalt()));
		user.setCreatetime(date);
		user.setAccount(addSchoolAccount.getAccount());
		user.setSchoolId(addSchoolAccount.getSchoolId());
		user.setAlipayPid(addSchoolAccount.getAlipayPid());
		Long roleId = userMapper.getRoleId(addSchoolAccount.getRoleName());
		user.setRoleid(String.valueOf(roleId));
		user.setDeptid(SystemConstans.DEPT_SCHOOL_INT);
		Integer userInsert = userMapper.insert(user);
		if (userInsert < 1) {
			throw new AppCheckException("school.insertUserError.code", "school.insertUserError.message");
		}

	}

	public void addSchoolInfo(AddSchoolInfo addSchoolInfo) {

		ShiroUser currentUser = ShiroKit.getUser();

		// 校验当前用户是否被删除
		User oneUsers = userMapper.selectById(currentUser.getId());
		if (1 != oneUsers.getStatus()) {
			throw new AppCheckException("school.schoolUserHaveDelete.code", "school.schoolUserHaveDelete.message");
		}
		// 校验密码是否包含中文字符
		String schoolPasswd = addSchoolInfo.getLoginPasswd();
		for (int i = 0; i < schoolPasswd.length(); i++) {
			if (StringUtil.isChinese(schoolPasswd.charAt(i))) {
				throw new AppCheckException("agent.passwdContainChinese.code", "agent.passwdContainChinese.message");
			}
		}
		// 校验是否是邮箱格式
		if (!StringUtil.isEmail(addSchoolInfo.getMailBox())) {
			throw new AppCheckException("system.mailFormatError.code", "system.mailFormatError.message");
		}
		List<SchoolInfo> schoolInfos = schoolInfoMapper.selectList(new EntityWrapper<>());
		schoolInfos.forEach(schoolInfo1 -> {
			// 校验支付宝PID是否重复
			if (addSchoolInfo.getAlipayPid().equals(schoolInfo1.getAlipayPid())) {
				throw new AppCheckException("school.aliPayRepeatError.code", "school.aliPayRepeatError.message");
			}
			// 校验微信商户号ID是否重复
			if (!"".equals(addSchoolInfo.getSubMchId())) {
				if (addSchoolInfo.getSubMchId().equals(schoolInfo1.getSubMchId())) {
					throw new AppCheckException("school.repeatSubMchIdError.code", "school.repeatSubMchIdError.message");
				}
			}
		});

		List<String> roleNames = currentUser.getRoleNames();
		String roles = roleNames.stream().collect(Collectors.joining(","));
		SchoolInfo schoolInfo = new SchoolInfo();
		schoolInfo.setCreatorRole(roles);
		Integer creatorId = currentUser.getId();
		schoolInfo.setCreatorId(creatorId.longValue());
		schoolInfo.setCreateTime(new Date());
		Long agentid = Long.valueOf(addSchoolInfo.getBelongAgentName());

		TAgentInfo selectByAgentId = agentInfoMapper.selectByAgentId(agentid);

		// 园所合伙人受数量限制
		if (selectByAgentId.getAgentType() == SystemConstans.TWO) {
			if (selectByAgentId.getSchoolCount() >= selectByAgentId.getSchoolCountLimit()) {
				throw new AppCheckException("school.addSchoolError.limit.code", "school.addSchoolError.limit.message", new Object[] { selectByAgentId.getSchoolCountLimit() });
			}
		}
		schoolInfo.setBelongAgent(agentid);
		BeanUtils.copyProperties(addSchoolInfo, schoolInfo);
		schoolInfo.setVersionNo(0);
		schoolInfo.setIsDelete(0);
		schoolInfo.setSchoolNature(addSchoolInfo.getSchoolNature());
		schoolInfo.setAlipayNumber(addSchoolInfo.getAlipayNumber());
		schoolInfo.setMailBox(addSchoolInfo.getMailBox());
		Integer schoolInsert = schoolInfoMapper.insert(schoolInfo);
		if (schoolInsert < 1) {
			throw new AppCheckException("school.addSchoolError.code", "school.addSchoolError.message");
		}

		// add schoolUser
		Map<String, Object> map = new HashMap();
		map.put("contact_tel", addSchoolInfo.getContactTel());
		List<SchoolInfo> selectByMap = schoolInfoMapper.selectByMap(map);
		if (null == selectByMap || selectByMap.size() == 0) {
			throw new AppCheckException("school.selectSchoolIDByNameError.code",
					"school.selectSchoolIDByNameError.message");
		}
		Long id = selectByMap.get(0).getId();
		User user = new User();
		String roleIdCustom = String.valueOf(roleMapper.getIdByName(SystemConstans.K_ROLENAME));
		Map<String, Object> schoolUserMap = new HashMap();
		schoolUserMap.put("account", addSchoolInfo.getContactTel());
		List<User> schoolUserList = userMapper.selectByMap(schoolUserMap);
		if (null != schoolUserList && schoolUserList.size() > 0) {
			schoolUserList.forEach(schoolUser -> {
				if (1 == schoolUser.getStatus()) {
					String schoolRoleIds = schoolUser.getRoleid();
					List<String> schoolRoleIdList = Arrays.asList(schoolRoleIds.split(","));
					schoolRoleIdList.forEach(schoolRoleid -> {
						if (roleIdCustom.equals(schoolRoleid)) {
							throw new AppCheckException("staff.schoolUserHaveExistError.code",
									"staff.schoolUserHaveExistError.message");
						}
						int staffId = roleMapper.getIdByName(SystemConstans.P_ROLNAME);
						if (String.valueOf(staffId).equals(schoolRoleid)) {
							throw new AppCheckException("staff.schoolUserHaveExistError.code",
									"staff.schoolUserHaveExistError.message");
						}
						int teacherId = roleMapper.getIdByName(SystemConstans.T_ROLENAME);
						if (String.valueOf(teacherId).equals(schoolRoleid)) {
							throw new AppCheckException("staff.userHaveExistError.code",
									"staff.userHaveExistError.message");
						}
						int agentUserId = roleMapper.getIdByName(SystemConstans.AU_ROLENAME);
						if (String.valueOf(agentUserId).equals(schoolRoleid)) {
							throw new AppCheckException("staff.userHaveExistError.code",
									"staff.userHaveExistError.message");
						}
					});
					schoolUser.setRoleid(schoolRoleIds + "," + roleIdCustom);
				} else {
					schoolUser.setRoleid(roleIdCustom);
				}
				schoolUser.setSalt(ShiroKit.getRandomSalt(5));
				schoolUser.setPassword(ShiroKit.md5(addSchoolInfo.getLoginPasswd(), schoolUser.getSalt()));
				schoolUser.setSchoolId(id);
				schoolUser.setStatus(1);
				schoolUser.setAccount(addSchoolInfo.getContactTel());
				schoolUser.setAlipayPid(addSchoolInfo.getAlipayPid());
				schoolUser.setName(addSchoolInfo.getSchoolContactPeople());
				schoolUser.setPhone(addSchoolInfo.getContactTel());
				schoolUser.setUpdatetime(new Date());
				schoolUser.setUpdateid(currentUser.getId());
				schoolUser.setCreatetime(new Date());
				schoolUser.setCreateid(currentUser.getId());
				Integer userUpdate = userMapper.updateById(schoolUser);
				if (userUpdate < 1) {
					throw new AppCheckException("school.addSchoolUserError.code",
							"school.addSchoolUserError.message");
				}
			});
		} else {
			user.setRoleid(roleIdCustom);
			user.setSalt(ShiroKit.getRandomSalt(5));
			user.setPassword(ShiroKit.md5(addSchoolInfo.getLoginPasswd(), user.getSalt()));
			user.setSchoolId(id);
			user.setStatus(1);
			user.setCreatetime(new Date());
			user.setAlipayPid(addSchoolInfo.getAlipayPid());
			user.setAccount(addSchoolInfo.getContactTel());
			user.setPhone(addSchoolInfo.getContactTel());
			user.setName(addSchoolInfo.getSchoolContactPeople());
			user.setCreateid(currentUser.getId());
			user.setDeptid(SystemConstans.DEPT_SCHOOL_INT);
			Integer userInsert = userMapper.insert(user);
			if (userInsert < 1) {
				throw new AppCheckException("school.addSchoolUserError.code", "school.addSchoolUserError.message");
			}
		}
		// schoolNo入库
		Map<String, Object> updateSchoolNoMap = new HashMap<>();
		updateSchoolNoMap.put("contact_tel", addSchoolInfo.getContactTel());
		List<SchoolInfo> schoolInfoList = schoolInfoMapper.selectByMap(updateSchoolNoMap);
		if (null != schoolInfoList && schoolInfoList.size() > 0) {
			schoolInfoList.forEach(schoolInfo2 -> {
				try {
					logger.info("学校信息为:{}", schoolInfo2);
					Map<String, String> schoolMap = eduPayCenter.setSchool(schoolInfo2).addSchool();
					logger.info("支付宝接口返回schoolNo:{}", schoolMap.get("aliSchoolNo"));
					schoolInfo2.setSchoolNo(schoolMap.get("aliSchoolNo"));
					Integer schoolUpdate = schoolInfoMapper.updateById(schoolInfo2);
					if (schoolUpdate < 1) {
						throw new AppCheckException("school.addSchoolUserError.code",
								"school.addSchoolUserError.message");
					}
				} catch (AppCheckException a) {
					throw new AppCheckException("school.addAliSchoolInfo.error", "school.addAliSchoolInfo.message",
							a.getMessage());
				}
			});
		} else {
			throw new AppCheckException("school.addSchoolUserError.code", "school.addSchoolUserError.message");
		}
		// 发送短信
		List<String> messageParamList = new ArrayList<>();
		messageParamList.add(addSchoolInfo.getContactTel());
		messageParamList.add(addSchoolInfo.getLoginPasswd());
		HashMap<String, String> param = new HashMap<>();
		param.put("mobile", addSchoolInfo.getContactTel());
		param.put("templateType", "0");
		param.put("msgKey", "pay.school.notice");
		param.put("params", JSON.toJSONString(messageParamList.toArray()));
		String response = HttpUtil.post(smsUrl, "utf-8", param);
		logger.info("[" + "短信返回码:" + "]" + response);
	}

	public void editSchoolInfo(EditSchoolInfo editSchoolInfo) {

		ShiroUser currentUser = ShiroKit.getUser();

		List<SchoolInfo> schoolInfos = schoolInfoMapper.selectList(new EntityWrapper<SchoolInfo>()
				.eq("is_delete", 0)
				.ne("id", editSchoolInfo.getSchoolId()));
		Optional.ofNullable(schoolInfos)
		.orElseThrow(() -> new AppCheckException("school.editSchoolInfoError.code",
				"school.editSchoolInfoError.message"));
		schoolInfos.forEach(schoolInfo1 -> {
			// 校验微信商户号ID是否重复
			if (!"".equals(editSchoolInfo.getSubMchId())) {
				if (editSchoolInfo.getSubMchId().equals(schoolInfo1.getSubMchId())) {
					throw new AppCheckException("school.repeatSubMchIdError.code", "school.repeatSubMchIdError.message");
				}
			}
		});

		// 校验是否是邮箱格式
		if (!StringUtil.isEmail(editSchoolInfo.getMailBox())) {
			throw new AppCheckException("system.mailFormatError.code", "system.mailFormatError.message");
		}

		List<String> roleNames = currentUser.getRoleNames();
		String roles = roleNames.stream().collect(Collectors.joining(","));
		SchoolInfo schoolInfo = schoolInfoMapper.selectById(editSchoolInfo.getSchoolId());
		schoolInfo.setSubMchId(editSchoolInfo.getSubMchId());
		schoolInfo.setVersionNo(editSchoolInfo.getVersionNo());
		schoolInfo.setUpdaterId(currentUser.getId().longValue());
		schoolInfo.setUpdateTime(new Date());
		schoolInfo.setUpdaterRole(roles);
		schoolInfo.setMailBox(editSchoolInfo.getMailBox());
		schoolInfo.setAlipayNumber(editSchoolInfo.getAlipayNumber());
		schoolInfo.setAlipayPid(editSchoolInfo.getAlipayPid());
		schoolInfo.setSchoolContactPeople(editSchoolInfo.getSchoolContactPeople());
		schoolInfo.setBelongAgent(Long.valueOf(editSchoolInfo.getBelongAgentName()));
		schoolInfo.setDetailAddr(editSchoolInfo.getDetailAddr());
		Integer editSchoolInfoUpdate = schoolInfoMapper.updateById(schoolInfo);
		if (editSchoolInfoUpdate < 1) {
			throw new AppCheckException("school.editSchoolInfoError.code", "school.editSchoolInfoError.message");
		}

		String contactTel = schoolInfo.getContactTel();
		List<User> userList = userMapper.selectList(new EntityWrapper<User>().eq("account", contactTel));
		if (null != userList) {
			userList.forEach(user -> {
				user.setName(editSchoolInfo.getSchoolContactPeople());
				user.setAlipayPid(editSchoolInfo.getAlipayPid());
				user.setUpdatetime(new Date());
				user.setUpdateid(currentUser.getId());
				Integer userInsert = userMapper.updateById(user);
				if (userInsert < 1) {
					throw new AppCheckException("school.editSchoolInfoError.code",
							"school.editSchoolInfoError.message");
				}
			});
		} else {
			throw new AppCheckException("school.editSchoolInfoError.code", "school.editSchoolInfoError.message");
		}
	}

	public SeeSchoolInfoVo seeSchoolInfo(QuerySeeSchoolInfo querySeeSchoolInfo) {

		ShiroUser currentUser = ShiroKit.getUser();
		User user = userMapper.selectById(currentUser.getId());
		if (1 != user.getStatus()) {
			throw new AppCheckException("workOrder.delete.code",
					"workOrder.delete.message", new Object[] { "无法查看学校" });
		}
		SchoolInfo schoolInfo = schoolInfoMapper.selectById(querySeeSchoolInfo.getSchoolId());
		Optional.ofNullable(schoolInfo)
		.orElseThrow(() -> new AppCheckException("school.searchSchoolInfoError.code",
				"school.searchSchoolInfoError.message"));
		SeeSchoolInfoVo seeSchoolInfoVo = new SeeSchoolInfoVo();
		BeanUtils.copyProperties(schoolInfo, seeSchoolInfoVo);
		seeSchoolInfoVo.setProvinceCode(regionMapper.getNameByCode(seeSchoolInfoVo.getProvinceCode()));
		seeSchoolInfoVo.setCityCode(regionMapper.getNameByCode(seeSchoolInfoVo.getCityCode()));
		seeSchoolInfoVo.setDistrictCode(regionMapper.getNameByCode(seeSchoolInfoVo.getDistrictCode()));
		TAgentInfo agentInfo = agentInfoMapper.selectById(schoolInfo.getBelongAgent());
		if (null == agentInfo) {
			throw new AppCheckException("school.seeBelongAgentError.code", "school.seeBelongAgentError.message");
		}
		List<AgentNamesVo> agentNamesVoList = new ArrayList<>();
		AgentNamesVo agentNamesVo = new AgentNamesVo();
		agentNamesVo.setAgentName(agentInfo.getAgentName());
		agentNamesVo.setProvince(regionMapper.getNameByCode(agentInfo.getProvince()));
		agentNamesVo.setCity(regionMapper.getNameByCode(agentInfo.getCity()));
		agentNamesVo.setArea(regionMapper.getNameByCode(agentInfo.getArea()));
		agentNamesVo.setAgentId(agentInfo.getId());
		agentNamesVoList.add(agentNamesVo);
		seeSchoolInfoVo.setAgentNamesVoList(agentNamesVoList);
		return seeSchoolInfoVo;
	}

	public List<HotSchoolVo> getHotSchoolData(Date startTime, Date endTime, Long agentId) {

		List<HotSchoolVo> hotSchoolVos = schoolInfoMapper
				.getHotSchoolData(startTime, DateUtil.addDaysToDate(endTime, 1), agentId);
		hotSchoolVos.forEach(hotSchoolVo -> {
			if (null == hotSchoolVo.getChargeAmount()) {
				hotSchoolVo.setChargeAmount(new BigDecimal("0"));
			}
		});
		return hotSchoolVos;
	}

	public SchoolAndFlowSituation getSchoolAndFlowData(QueryHotData queryHotData) {

		Map<String, Object> map = new HashMap<>();
		map.put("startTime", queryHotData.getStartTime());
		map.put("endTime", DateUtil.addDaysToDate(queryHotData.getEndTime(), 1));
		map.put("agentId", queryHotData.getAgentId());
		int schoolNum = schoolInfoMapper.getTotalSchoolNum(map);
		SchoolAndFlowSituation schoolAndFlowSituation = new SchoolAndFlowSituation();
		if (null == billDetailMapper.getFlowByDate(map)) {
			schoolAndFlowSituation.setFlow(new BigDecimal("0"));
		} else {
			schoolAndFlowSituation.setFlow(billDetailMapper.getFlowByDate(map));
		}
		schoolAndFlowSituation.setNewSchoolCount(schoolNum);
		return schoolAndFlowSituation;
	}

	public StatisticsSchoolVo getStatisticsSchoolData(QueryHotData queryHotData) {

		Map<String, Object> map = new HashMap<>();
		map.put("startTime", queryHotData.getStartTime());
		map.put("endTime", DateUtil.addDaysToDate(queryHotData.getEndTime(), 1));
		int schoolNum = schoolInfoMapper.getTotalSchoolNum(map);
		int totalSchoolNum = schoolInfoMapper.selectCount(new EntityWrapper<SchoolInfo>().eq("is_delete", 0));
		StatisticsSchoolVo statisticsSchoolVo = new StatisticsSchoolVo();
		statisticsSchoolVo.setNewSchoolNum(schoolNum);
		statisticsSchoolVo.setTotalSchoolNum(totalSchoolNum);

		return statisticsSchoolVo;
	}

	public List<EveryDayCountVo> getSchoolCountData(QueryHotData queryHotData) {

		ShiroUser currentUser = ShiroKit.getUser();
		User user = userMapper.selectById(currentUser.getId());
		if (1 != user.getStatus()) {
			throw new AppCheckException("workOrder.delete.code",
					"workOrder.delete.message", new Object[] { "无法查看学校" });
		}

		Date start, end;
		if (queryHotData.getStartTime() == null || queryHotData.getEndTime() == null) {
			end = new Date();
			start = DateUtil.addDaysToDate(end, -7);
			List<Date> formateDate = DateUtil.formateDate(start, end);
			start = formateDate.get(0);
			end = formateDate.get(1);
			queryHotData.setStartTime(start);
			queryHotData.setEndTime(end);
		}

		ZoneId zoneId = ZoneId.systemDefault();
		LocalDate startLocalDate = queryHotData.getStartTime().toInstant().atZone(zoneId).toLocalDate();
		LocalDate endLocalDate = queryHotData.getEndTime().toInstant().atZone(zoneId).toLocalDate();
		List<String> allDay = DateUtil.collectLocalDates(startLocalDate, endLocalDate);
		List<EveryDayCountVo> everyDayCountVoList = new ArrayList<>();
		List<CurrentSchoolDataVo> currentSchoolDataVoListByDb = null;
		Date endTime = DateUtil.addDaysToDate(queryHotData.getEndTime(), 1);
		Long userId = queryHotData.getAgentId();
		if (null == queryHotData.getAgentId()) {
			currentSchoolDataVoListByDb = schoolInfoMapper
					.getCurrentSchoolNum(queryHotData.getStartTime(), endTime, queryHotData.getAgentId());
		} else {
			Map<String, Object> userMap = new HashMap<>();
			userMap.put("id", userId);
			currentSchoolDataVoListByDb = schoolInfoMapper
					.getCurrentSchoolNum(queryHotData.getStartTime(), endTime, userId);
		}
		for (String oneDay : allDay) {
			EveryDayCountVo everyDayCountVo = new EveryDayCountVo();
			everyDayCountVo.setDay(oneDay);
			Map<String, Object> map = new HashMap<>();
			map.put("startTime", null);
			map.put("endTime", DateUtil.addDaysToDate(DateUtil.parseDate(oneDay), 1));
			map.put("agentId", queryHotData.getAgentId());
			int totalSchoolNum = schoolInfoMapper.getTotalSchoolNum(map);
			everyDayCountVo.setTotalSchoolData(totalSchoolNum);
			int paySchoolData = 0;

			if (userId != null) {
				Long agentId = user.getAgentId();

				Map<String, Object> columnMap = new HashMap<String, Object>();
				columnMap.put("belong_agent", agentId);
				List<SchoolInfo> selectByMap = schoolInfoMapper.selectByMap(columnMap);
				if (CollectionUtils.isEmpty(selectByMap)) {
					throw new AppCheckException("school.user.noSchool.code", "school.user.noSchool.message");
				}
				List<Long> schoollist = selectByMap.stream().map(SchoolInfo::getId).collect(Collectors.toList());
				paySchoolData = billDetailMapper.countSchool(oneDay + " 00:00:00", oneDay + " 23:59:59", schoollist);

			} else {
				paySchoolData = billDetailMapper.countSchool(oneDay + " 00:00:00", oneDay + " 23:59:59", null);
			}
			// 新增缴费学校数
			everyDayCountVo.setPaySchoolData(paySchoolData);

			for (CurrentSchoolDataVo currentSchoolDataVo1 : currentSchoolDataVoListByDb) {
				Date dbTime = currentSchoolDataVo1.getCurrentDay();
				if (oneDay.equals(DateUtil.getDay(dbTime))) {
					everyDayCountVo.setCurrentSchoolData(currentSchoolDataVo1.getCurrentCount());
					break;
				} else {
					everyDayCountVo.setCurrentSchoolData(0);
				}
			}
			everyDayCountVoList.add(everyDayCountVo);
		}
		return everyDayCountVoList;
	}

	public List<EveryFlowCountVo> getFlowCountData(QueryHotData queryHotData) {

		// 获取一个时间段之类的各个日期
		ZoneId zoneId = ZoneId.systemDefault();
		LocalDate startLocalDate = queryHotData.getStartTime().toInstant().atZone(zoneId).toLocalDate();
		LocalDate endLocalDate = queryHotData.getEndTime().toInstant().atZone(zoneId).toLocalDate();
		List<String> allDay = DateUtil.collectLocalDates(startLocalDate, endLocalDate);

		List<EveryFlowCountVo> everyFlowCountVoList = new ArrayList<>();
		Date endTime = DateUtil.addDaysToDate(queryHotData.getEndTime(), 1);
		List<CurrentFlowDataVo> currentFlowDataVoList = billDetailMapper
				.getCurrentFlowNum(queryHotData.getStartTime(), endTime, queryHotData.getAgentId());
		for (String oneDay : allDay) {
			EveryFlowCountVo everyFlowCountVo = new EveryFlowCountVo();
			everyFlowCountVo.setEveryDay(oneDay);
			if (currentFlowDataVoList.size() == 0) {
				everyFlowCountVo.setCurrentFlow(new BigDecimal("0"));
			} else {
				for (CurrentFlowDataVo currentFlowDataVo1 : currentFlowDataVoList) {
					if (oneDay.equals(DateUtil.getDay(currentFlowDataVo1.getCurrentDay()))) {
						everyFlowCountVo.setCurrentFlow(currentFlowDataVo1.getCurrentFlow());
						break;
					} else {
						everyFlowCountVo.setCurrentFlow(new BigDecimal("0"));
					}
				}
			}
			Map<String, Object> map = new HashMap<>();
			map.put("startTime", null);
			map.put("endTime", DateUtil.addDaysToDate(DateUtil.parseDate(oneDay), 1));
			map.put("agentId", queryHotData.getAgentId());
			if (null == billDetailMapper.getFlowByDate(map)) {
				everyFlowCountVo.setTotalFlow(new BigDecimal("0"));
			} else {
				everyFlowCountVo.setTotalFlow(billDetailMapper.getFlowByDate(map));
			}
			everyFlowCountVoList.add(everyFlowCountVo);
		}
		return everyFlowCountVoList;
	}

	public void exportExcel(HttpServletResponse response, QuerySchoolInfo querySchoolInfo) {

		extracted(querySchoolInfo);
		List<ExportSchoolInfoVo> exportSchoolInfoVoList = schoolInfoMapper.getExportSchoolInfo(querySchoolInfo);
		Optional.ofNullable(exportSchoolInfoVoList)
		.orElseThrow(
				() -> new AppCheckException("school.selectUserError.code", "school.selectUserError.message"));
		exportSchoolInfoVoList.forEach(exportSchoolInfoVo -> {
			if (null == exportSchoolInfoVo.getFlow()) {
				exportSchoolInfoVo.setFlow(new BigDecimal(0));
			}
		});
		try {
			response.reset();
			// 导出文件名称
			String filename = "学校信息.xls";
			// 设定输出文件头
			response.setHeader("Content-disposition", "attachment; filename="
					+ new String(filename.getBytes("GB2312"), "8859_1"));
			ExportParams exportParams = new ExportParams();
			exportParams.setStyle(ExcelExportStylerBorderImpl.class);
			exportParams.setTitle("学校明细");
			exportParams.setSheetName("学校信息");
			Workbook workbook = ExcelExportUtil.exportExcel(exportParams, ExportSchoolInfoVo.class,
					exportSchoolInfoVoList);
			workbook.write(response.getOutputStream());
		} catch (IOException e) {
			throw new AppCheckException("school.exportSchoolInfo.code", "school.exportSchoolInfo.message",
					e.getMessage());
		}
	}

	@Async
	public void sendMail(String recipientMailbox, String contactTel, String schoolName, String passwd,
			String alipayNumber) {

		try {
			logger.info("开始发送邮件");
			// System.setProperty("java.net.preferIPv4Stack", "true");
			MimeMessage message = mailSender.createMimeMessage();
			MimeMessageHelper helper = new MimeMessageHelper(message, true);
			helper.setFrom(Sender);
			helper.setTo(recipientMailbox);
			helper.setSubject(subject);
			Map<String, Object> model = new HashMap<>();
			model.put("contactTel", contactTel);
			model.put("passwd", passwd);
			model.put("alipayNumber", alipayNumber);
			model.put("schoolName", schoolName);
			// 读取ftl模板
			Template template = freeMarkerConfigurer.getConfiguration().getTemplate("email.ftl");
			String html = FreeMarkerTemplateUtils.processTemplateIntoString(template, model);
			helper.setText(html, true);
			mailSender.send(message);
			logger.info("邮件发送成功!");
		} catch (Exception e) {
			logger.error("邮件发送失败!,错误信息:{}", e.getMessage());
		}
	}

	/**
	 * 方法描述: [学校每月短信统计.]<br/>
	 * 初始作者: 钟小平<br/>
	 * 创建日期: 2018年7月18日-下午8:38:41<br/>
	 * 开始版本: 2.0.0<br/>
	 * =================================================<br/>
	 * 修改记录：<br/>
	 * 修改作者 日期 修改内容<br/>
	 * ================================================<br/>
	 * 
	 * @param querySmsData
	 * @param flag
	 * @return
	 *         List<EveryMonthSmsCountVo>
	 */
	public List<EveryMonthSmsCountVo> getSchoolSmsCountData(QuerySmsData querySmsData, boolean flag) {

		ShiroUser currentUser = ShiroKit.getUser();
		User oneUser = userMapper.selectById(currentUser.getId());
		if (!oneUser.getStatus().equals(SystemConstans.YES)) {
			throw new AppCheckException("school.user.notActive.code", "school.user.notActive.message");
		}
		Long schoolId = null;
		if (flag) {
			schoolId = querySmsData.getSchoolId();
		} else {
			schoolId = oneUser.getSchoolId();
			if (schoolId == null) {
				throw new AppCheckException("school.user.noSchool.code", "school.user.noSchool.message");
			}
		}
		Date start, end;
		extracted(querySmsData);
		if (querySmsData.getStartTime() == null || querySmsData.getEndTime() == null) {
			end = DateUtil.getEndDayOfMonth(new Date());
			start = DateUtil.addMonthsToDate(end, -12);
			start = DateUtil.getStartDayOfMonth(start);
			List<Date> formateDate = DateUtil.formateDate(start, end);
			start = formateDate.get(0);
			end = formateDate.get(1);
			querySmsData.setStartTime(start);
			querySmsData.setEndTime(end);
		}

		ZoneId zoneId = ZoneId.systemDefault();
		LocalDate startLocalDate = querySmsData.getStartTime().toInstant().atZone(zoneId).toLocalDate();
		LocalDate endLocalDate = querySmsData.getEndTime().toInstant().atZone(zoneId).toLocalDate();
		List<String> allMonth = DateUtil.collectLocalMonthDates(startLocalDate, endLocalDate);
		List<EveryMonthSmsCountVo> everyMonthSmsCountVo = new ArrayList<>();

		for (int i = 0; i < allMonth.size(); i++) {
			EveryMonthSmsCountVo vo = new EveryMonthSmsCountVo();
			String substring = allMonth.get(i).substring(0, 7);
			vo.setMonth(substring);
			Date endOfDay = DateUtil.getEndDayOfMonth(DateUtil.parseDate(allMonth.get(i)));

			if (schoolId != null) {
				int selectCount = smsSendMapper.selectCount(new EntityWrapper<SmsSend>().eq("school_id", schoolId).eq("status", SystemConstans.YES)
						.ge("create_time", substring + "-01 00:00:00")
						.le("create_time", endOfDay)
						);
				vo.setMonthSchoolSmsData(selectCount);
			} else {
				int selectCount = smsSendMapper.selectCount(new EntityWrapper<SmsSend>().eq("status", SystemConstans.YES)
						.ge("create_time", substring + "-01 00:00:00")
						.le("create_time", endOfDay)
						);

				vo.setMonthSchoolSmsData(selectCount);
			}
			everyMonthSmsCountVo.add(vo);
		}
		return everyMonthSmsCountVo;
	}

	/**
	 * 方法描述: [学校收费时段情况.]<br/>
	 * 初始作者: 钟小平<br/>
	 * 创建日期: 2018年7月19日-下午5:55:22<br/>
	 * 开始版本: 2.0.0<br/>
	 * =================================================<br/>
	 * 修改记录：<br/>
	 * 修改作者 日期 修改内容<br/>
	 * ================================================<br/>
	 * 
	 * @param querySmsData
	 * @return
	 *         List<DayOrHourChargeCountVo>
	 */
	public List<DayOrHourChargeCountVo> getSchoolChargeSlotData(QuerySmsData querySmsData) {

		ShiroUser currentUser = ShiroKit.getUser();
		User oneUser = userMapper.selectById(currentUser.getId());
		if (!oneUser.getStatus().equals(SystemConstans.YES)) {
			throw new AppCheckException("school.user.notActive.code", "school.user.notActive.message");
		}
		Long schoolId = oneUser.getSchoolId();
		if (schoolId == null) {
			throw new AppCheckException("school.user.noSchool.code", "school.user.noSchool.message");
		}

		Date start, end;
		if (querySmsData.getStartTime() == null || querySmsData.getEndTime() == null) {
			end = new Date();
			start = DateUtil.addDaysToDate(end, -10);
			List<Date> formateDate = DateUtil.formateDate(start, end);
			start = formateDate.get(0);
			end = formateDate.get(1);
			querySmsData.setStartTime(start);
			querySmsData.setEndTime(end);
		} else {
			List<Date> formateDate = DateUtil.formateDate(querySmsData.getStartTime(), querySmsData.getEndTime());
			start = formateDate.get(0);
			end = formateDate.get(1);
			querySmsData.setStartTime(start);
			querySmsData.setEndTime(end);
		}
		ZoneId zoneId = ZoneId.systemDefault();
		LocalDate startLocalDate = querySmsData.getStartTime().toInstant().atZone(zoneId).toLocalDate();
		LocalDate endLocalDate = querySmsData.getEndTime().toInstant().atZone(zoneId).toLocalDate();
		List<DayOrHourChargeCountVo> everyDayCountVoList = new ArrayList<DayOrHourChargeCountVo>();
		if (startLocalDate.equals(endLocalDate)) {
			LocalDateTime startTime = querySmsData.getStartTime().toInstant().atZone(zoneId).toLocalDateTime();
			LocalDateTime endTime = querySmsData.getEndTime().toInstant().atZone(zoneId).toLocalDateTime();
			List<String> collectLocalDayDates = DateUtil.collectLocalDayDates(startTime, endTime);
			for (String oneDay : collectLocalDayDates) {
				DayOrHourChargeCountVo everyDayCountVo = new DayOrHourChargeCountVo();
				everyDayCountVo.setTime(oneDay.substring(11, 13) + "时");
				DayOrHourChargeCountVo daySchoolChargeData = billDetailMapper.billSuccessStatistics(oneDay.substring(0, 10) + " " + oneDay.substring(11, 13) + ":00:00",
						oneDay.substring(0, 10) + " " + oneDay.substring(11, 13) + ":59:59", schoolId);
				everyDayCountVo.setSchoolChargeData(daySchoolChargeData.getSchoolChargeData());
				everyDayCountVo.setSchoolChargePeople(daySchoolChargeData.getSchoolChargePeople());
				everyDayCountVoList.add(everyDayCountVo);
			}

		} else {
			List<String> allDay = DateUtil.collectLocalDates(startLocalDate, endLocalDate);

			for (String oneDay : allDay) {
				DayOrHourChargeCountVo everyDayCountVo = new DayOrHourChargeCountVo();
				everyDayCountVo.setTime(oneDay);
				DayOrHourChargeCountVo daySchoolChargeData = billDetailMapper.billSuccessStatistics(oneDay + " 00:00:00", oneDay + " 23:59:59", schoolId);
				everyDayCountVo.setSchoolChargeData(daySchoolChargeData.getSchoolChargeData());
				everyDayCountVo.setSchoolChargePeople(daySchoolChargeData.getSchoolChargePeople());
				everyDayCountVoList.add(everyDayCountVo);
			}
		}
		return everyDayCountVoList;
	}

	private void extracted(QuerySmsData query) {

		if (query.getStartTime() != null) {
			query.setStartTime(DateUtil.formate(query.getStartTime(), true));
		}
		if (query.getEndTime() != null) {
			query.setEndTime(DateUtil.formate(query.getEndTime(), false));
		}
	}

	private void extracted(QuerySchoolInfo query) {

		if (query.getStartTime() != null) {
			query.setStartTime(DateUtil.formate(query.getStartTime(), true));
		}
		if (query.getEndTime() != null) {
			query.setEndTime(DateUtil.formate(query.getEndTime(), false));
		}
	}

	public List listSchoolTeacher() {

		ShiroUser currentUser = ShiroKit.getUser();
		User oneUser = userMapper.selectById(currentUser.getId());
		if (!oneUser.getStatus().equals(SystemConstans.YES)) {
			throw new AppCheckException("school.user.notActive.code", "school.user.notActive.message");
		}
		Long schoolId = oneUser.getSchoolId();
		if (schoolId == null) {
			throw new AppCheckException("school.user.noSchool.code", "school.user.noSchool.message");
		}
		List<User> selectList = userMapper.selectList(new EntityWrapper<User>().eq("school_id", schoolId).eq("status", SystemConstans.YES));
		List<KeyValue> list = new ArrayList<KeyValue>();
		if (CollectionUtils.isNotEmpty(selectList)) {
			selectList.forEach(x -> {
				KeyValue kv = new KeyValue();
				kv.setKey(x.getId());
				kv.setValue(x.getName());
				list.add(kv);
			});
		}
		return list;
	}

	/**
	 * 方法描述: [学校收费项列表.]<br/>
	 * 初始作者: 钟小平<br/>
	 * 创建日期: 2018年8月15日-下午3:54:44<br/>
	 * 开始版本: 2.0.0<br/>
	 * =================================================<br/>
	 * 修改记录：<br/>
	 * 修改作者 日期 修改内容<br/>
	 * ================================================<br/>
	 * 
	 * @return
	 *         List<SchoolPayItem>
	 */
	public List<SchoolPayItem> listSchoolPayItem() {

		ShiroUser currentUser = ShiroKit.getUser();
		User oneUser = userMapper.selectById(currentUser.getId());
		if (!oneUser.getStatus().equals(SystemConstans.YES)) {
			throw new AppCheckException("school.user.notActive.code", "school.user.notActive.message");
		}
		Long schoolId = oneUser.getSchoolId();
		if (schoolId == null) {
			throw new AppCheckException("school.user.noSchool.code", "school.user.noSchool.message");
		}
		List<SchoolPayItem> selectList = schoolPayItemMapper.selectList(new EntityWrapper<SchoolPayItem>()
				.eq("is_delete", 0)
				.eq("school_id", schoolId).orderBy("id", false));
		return selectList;
	}

	/**
	 * 方法描述: [新增修改删除收费项.]<br/>
	 * 初始作者: 钟小平<br/>
	 * 创建日期: 2018年8月15日-下午4:09:07<br/>
	 * 开始版本: 2.0.0<br/>
	 * =================================================<br/>
	 * 修改记录：<br/>
	 * 修改作者 日期 修改内容<br/>
	 * ================================================<br/>
	 * 
	 * @param addSchoolPayItem
	 * @param i
	 *            void
	 */
	public void addSchoolPayItem(AddSchoolPayItem addSchoolPayItem, int flag) {

		ShiroUser currentUser = ShiroKit.getUser();
		User oneUser = userMapper.selectById(currentUser.getId());
		if (!oneUser.getStatus().equals(SystemConstans.YES)) {
			throw new AppCheckException("school.user.notActive.code", "school.user.notActive.message");
		}
		Long schoolId = oneUser.getSchoolId();
		if (schoolId == null) {
			throw new AppCheckException("school.user.noSchool.code", "school.user.noSchool.message");
		}
		SchoolPayItem entity = new SchoolPayItem();
		BeanUtils.copyProperties(addSchoolPayItem, entity);
		entity.setSchoolId(schoolId);

		if (addSchoolPayItem.getId() != null) {
			SchoolPayItem oldItem = schoolPayItemMapper.selectById(addSchoolPayItem.getId());
			if (flag == 1) {
				entity.setIsDelete(SystemConstans.YES);
			} else {
				Map<String, Object> payItemParam = new HashMap<String, Object>();
				payItemParam.put("name", addSchoolPayItem.getName());
				payItemParam.put("school_id", schoolId);
				payItemParam.put("is_delete", SystemConstans.NO);
				List<SchoolPayItem> payItem = schoolPayItemMapper.selectByMap(payItemParam);
				if (CollectionUtils.isNotEmpty(payItem) && !oldItem.getName().equals(addSchoolPayItem.getName())) {
					throw new AppCheckException("school.schoolPayItem.exit.code", "school.schoolPayItem.exit.message", addSchoolPayItem.getName());
				}
			}
			entity.setUpdaterId(Long.parseLong(oneUser.getId() + ""));
			entity.setUpdateTime(new Date());
			entity.setUpdaterRole(oneUser.getRoleid());
			schoolPayItemMapper.updateById(entity);
		} else {
			Map<String, Object> payItemParam = new HashMap<String, Object>();
			payItemParam.put("name", addSchoolPayItem.getName());
			payItemParam.put("is_delete", SystemConstans.NO);
			payItemParam.put("school_id", schoolId);
			List<SchoolPayItem> payItem = schoolPayItemMapper.selectByMap(payItemParam);
			if (CollectionUtils.isNotEmpty(payItem)) {
				throw new AppCheckException("school.schoolPayItem.exit.code", "school.schoolPayItem.exit.message", addSchoolPayItem.getName());
			}

			Map<String, Object> columnMap = new HashMap<String, Object>();
			columnMap.put("is_delete", SystemConstans.NO);
			columnMap.put("school_id", schoolId);
			List<SchoolPayItem> selectByMap = schoolPayItemMapper.selectByMap(columnMap);
			if (selectByMap.size() >= 20) {
				throw new AppCheckException("school.schoolPayItem.overfull.code", "school.schoolPayItem.overfull.message");
			}
			entity.setCreatorId(Long.parseLong(oneUser.getId() + ""));
			entity.setCreateTime(new Date());
			entity.setIsDelete(SystemConstans.NO);
			entity.setCreatorRole(oneUser.getRoleid());
			schoolPayItemMapper.insert(entity);
		}

	}

	/**
	 * 方法描述: [学校账单对应收费项目.]<br/>
	 * 初始作者: 钟小平<br/>
	 * 创建日期: 2018年8月22日-下午6:20:06<br/>
	 * 开始版本: 2.0.0<br/>
	 * =================================================<br/>
	 * 修改记录：<br/>
	 * 修改作者 日期 修改内容<br/>
	 * ================================================<br/>
	 * 
	 * @param billId
	 * @param schoolId
	 * @return
	 *         List<SchoolPayItem>
	 */
	public SchoolPayItemVo listSchoolPayItemByBillId(Long billId, Long schoolId) {

		Bill bill = new Bill();
		bill.setSchoolId(schoolId);
		bill.setId(billId);
		bill.setIsDelete(SystemConstans.NO);
		Bill selectOne = billMapper.selectOne(bill);
		if (selectOne == null || new Date().after(selectOne.getBillEndTime())) {
			throw new AppCheckException("school.zhangdan.notExitorOverTime.code", "school.zhangdan.notExitorOverTime.message");
		}
		List<SchoolPayItem> schoolPayItems = schoolPayItemMapper.selectByBillId(billId, schoolId);
		SchoolPayItemVo vo = new SchoolPayItemVo();
		vo.setPayItems(schoolPayItems);
		vo.setBillId(billId);
		vo.setBillName(selectOne.getName());
		return vo;
	}
}
